<?php
if(!empty($_GET['id'])){
include('fungsi_depan.php');
$cat = kategori();
$data = baca($_GET['id']);
?>
<html>
<head>
<title><?php echo $data['judul'];?></title>
<link href="css/global.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- BEGIN HEADER -->
<center>
  <div class="header"><h1 class="judul-atas"><a href="../pwl">budinews.com</a></h1>
  <p>portal berita terlengkap</p>
  </div>
 </center>
<!-- END HEADER -->
<!-- BEGIN NAV -->
<div id="nav">
  <ul>
	<li><a href="../pwl">Home</a></li>
    <?php
		foreach ($cat as $kategori){
			echo "<li><a href='kategori.php?id=".$kategori."'>".$kategori."</a></li>";
		}
		?>
  </ul>
</div>
<!-- END NAV -->
<br/><br/>
<!-- BEGIN CONTENT WRAPPER -->
<div id="content-wrapper">
  <!-- BEGIN MAIN -->
  <div id="main">
    <div id="headlines">
     <h2><a href="detail.php?id=<?php echo $data['id_berita'];?>"><?php echo $data['judul'];?></a></h2>
	 <small><?php echo $data['waktu'];?> | di post oleh Budi | dilihat <?php echo $data['counter'];?> kali | <?php hitung_komentar($_GET['id']);?></small>
	 <hr>
	 <center>
	 <img src="gambar/<?php echo $data['gambar'];?>" alt="" width="500px" height="auto"></center>	 
	 <p><?php echo $data['detail'];?></p>
	 <h3>Berita Terkait</h3>
	 <ul>
		<?php berita_terkait($data['id_kategori']);?>
	 </ul>
    </div>
	<hr/>
	<h3>Apa Kata Mereka?</h3>
	<?php hitung_komentar($_GET['id']);?>
	<hr/>
	<?php tampil_komentar($_GET['id']);?>
	<h3>Komentar</h3>
	<form action="" method="post">
	<table>
	<tr>
		<td>Nama</td>
		<td>:</td>
		<td><input type="text" name="nama_komentar" style="width: 400px;"/></td>
	</tr>
	<tr>
		<td>E-mail</td>
		<td>:</td>
		<td><input type="text" name="email_komentar" style="width: 400px;"/></td>
	</tr>
	<tr>
		<td>Isi Komentar</td>
		<td>:</td>
		<td><textarea type="text" name="isi_komentar" col="100" rows="10"style="width: 398px;" ></textarea></td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td><input type="submit" /></td>
	</tr>
	</table>
	</form>
  </div>
  <!-- END MAIN -->
  <!-- BEGIN SIDEBARS -->
  <div id="sidebars">
	<h2 class="heading-blue">Cari Berita</h2>
	<form action="cari.php" method="get">
		<input type="text" name="cari" style="width: 233px;"/><input type="submit" value="cari"/>
	</form><br/>
	<h2 class="heading-blue">Olahraga</h2>
    <?php olahraga();?>
	<h2 class="heading-blue">Berita Dunia</h2>
    <?php dunia();?>
	<h2 class="heading-blue">Politik</h2>
	<?php politik();?>
	<h2 class="heading-blue">Kesehatan</h2>
    <?php kesehatan();?>
	<h2 class="heading-blue">Tekno</h2>
    <?php tekno();?>
  </div>
  <!-- END SIDEBARS -->
</div>
<!-- END CONTENT WRAPPER-->
<!-- BEGIN EXTRAS -->
<div id="extras">
  <div id="recommended">
    <h2 class="heading">Berita Terpopuler</h2>
    <ul>
	<?php $banyak = terbanyak();
		#print_r($banyak);exit;
		while($ter = mysql_fetch_assoc($banyak)){
		echo '<li><a href="detail.php?id='.$ter['id_berita'].'">'.$ter['judul'].' &raquo;</a></li>';
		}
	?>
    </ul>
  </div>
  <div id="programs">
    <h2 class="heading">Unik</h2>
    <ul>
	<?php $banyak = terunik();
		#print_r($banyak);exit;
		while($ter = mysql_fetch_assoc($banyak)){
		echo '<li><a href="detail.php?id='.$ter['id_berita'].'">'.$ter['judul'].' &raquo;</a></li>';
		}
	?>
    </ul>
</div>
  <div id="cartoon">
    <h2 class="heading">Film</h2>
    <ul>
	<?php $banyak = film();
		while($ter = mysql_fetch_assoc($banyak)){
		echo '<li><a href="detail.php?id='.$ter['id_berita'].'">'.$ter['judul'].' &raquo;</a></li>';
		}
	?>
    </ul>
</div>
<!-- END EXTRAS -->
<!-- BEGIN FOOTER -->
<div id="footer">
  <ul>
    <li>&copy;<?php echo date('Y');?> | <a href="#">budinews.com</a></li>
  </ul>
</div>
<!-- END FOOTER -->
</html>
<?php
if(!empty($_POST)){
	komentar($_GET['id'], $_POST['isi_komentar'], $_POST['nama_komentar'], $_POST['email_komentar']);
}
}else{
	echo "<script>
			window.location = '../pwl';
	</script>";
}
?>
